//
//  LS_DestinatViewModel.m
//  breadPro
//
//  Created by 刘文超 on 2019/7/5.
//  Copyright © 2019 刘文超. All rights reserved.
//

#import "LS_DestinatViewModel.h"
#import "LS_DestinationModel.h"
#import "LS_WebViewModel.h"
#import "LS_MediatorAction+LS_WebViewController.h"
#import "LS_WebViewController.h"
@interface LS_DestinatViewModel()
@property(nonatomic,strong)id<LS_ViewModelService> services;
@end
@implementation LS_DestinatViewModel
-(instancetype)initWithService:(id<LS_ViewModelService>)services
{
    if (self =[super init]) {
        _services = services;
        [self initialize];
    }return self;
}
-(void)setMyVC:(UIViewController *)MyVC
{
    _MyVC = MyVC;
    
}
-(void)initialize
{
    
    _feedDataCommand = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
        return [[[self.services getDestineService] requestDestineSingnal:Destine_URL] doNext:^(id x) {
            self.feedData = [NSArray arrayWithArray:x[DestinDataKey]];
            self.videoData = [NSArray arrayWithArray:x[DestinVideoKey]];
        }];
    }];
    
    _feedDetailCommand = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
        NSLog(@"点击了详情");
        LS_DestinationModel *model = input;
        NSString *requestURL = [NSString stringWithFormat:@"http://web.breadtrip.com/hunter/product/%@/?bts=app_discover_share",model.product_id];
        LS_WebViewModel *viewModel = [[LS_WebViewModel alloc]initWithServices:self.services param:@{WebViewTypekey:@"设计详情",WebNavBarStyleTypekey:@(LSWebNavBarStyleTypeNomer),WebViewTypekey:@(LSWebTypeDestinDetialType),RequestURLkey:requestURL}];
        //第一种方法可以穿一个VC对象过来直接跳转
        LS_WebViewController *webView = [[LS_WebViewController alloc]initWithViewModel:viewModel];
        [self.MyVC.navigationController pushViewController:webView animated:YES];
        //第二种方法。获取当前界面来跳转
//        [[LS_MediatorAction sharedInstance] pushWebViewControllerWithViewModel:viewModel];
        return [RACSignal empty];
    }];
    
    
    _commentLinkCommand = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(NSNumber *productID) {
        NSLog(@"点击了评论");
        NSString *requestURL = [NSString stringWithFormat:@"http://web.breadtrip.com/hunter/product/%@/comments/",productID];
        LS_WebViewModel *viewModel = [[LS_WebViewModel alloc]initWithServices:self.services param:@{WebTitlekey:@"评论详情",WebNavBarStyleTypekey:@(LSWebNavBarStyleTypeNomer),WebViewTypekey:@(LSWebTypeDestinDetialType),RequestURLkey:requestURL}];
        
        LS_WebViewController *webView = [[LS_WebViewController alloc]initWithViewModel:viewModel];
        [self.MyVC.navigationController pushViewController:webView animated:YES];

        return [RACSignal empty];
    }];
    
}
@end
